//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Windows.Media.Effects;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    public class ReflectionEffect : ImageEffect
    {
        private RectAlignment algn;
        private int blurRad;
        private int dir;
        private int dist;
        private int endA;
        private int endPos;
        private int fadeDir;
        private int kx;
        private int ky;
        private bool rotWithShape = true;

        private int stA;

        private int stPos;
        private double sx;
        private double sy;

        public int BlurRadius
        {
            get { return blurRad; }
            set { blurRad = value; }
        }

        public int StA
        {
            get { return stA; }
            set { stA = value; }
        }

        public int StPos
        {
            get { return stPos; }
            set { stPos = value; }
        }

        public int EndA
        {
            get { return endA; }
            set { endA = value; }
        }

        public int EndPos
        {
            get { return endPos; }
            set { endPos = value; }
        }

        public int Dist
        {
            get { return dist; }
            set { dist = value; }
        }

        public int Dir
        {
            get { return dir; }
            set { dir = value; }
        }

        public int FadeDir
        {
            get { return fadeDir; }
            set { fadeDir = value; }
        }

        public double Sx
        {
            get { return sx; }
            set { sx = value; }
        }

        public double Sy
        {
            get { return sy; }
            set { sy = value; }
        }

        public int Kx
        {
            get { return kx; }
            set { kx = value; }
        }

        public int Ky
        {
            get { return ky; }
            set { ky = value; }
        }

        public RectAlignment Algn
        {
            get { return algn; }
            set { algn = value; }
        }

        public bool RotateWithShape
        {
            get { return rotWithShape; }
            set { rotWithShape = value; }
        }


        internal override void ReadXmlCore(ReadContext context)
        {
            using (var c = context.Read("reflection"))
            {
                BlurRadius = c.GetOptionalInteger("blurRad", 0);
                StA = c.GetOptionalInteger("stA", 100000);
                stPos = c.GetOptionalInteger("stPos", 0);
                endA = c.GetOptionalInteger("endA", 0);
                endPos = c.GetOptionalInteger("endPos", 100000);
                dist = c.GetOptionalInteger("dist", 0);
                dir = c.GetOptionalInteger("dir", 0);
                fadeDir = c.GetOptionalInteger("fadeDir", 5400000);
                sx = SerializationHelper.GetOptionalPercent(c, "sx", 100000);
                sy = SerializationHelper.GetOptionalPercent(c, "sy", 100000);
                kx = c.GetOptionalInteger("kx", 0);
                ky = c.GetOptionalInteger("ky", 0);
                algn = c.GetOptionalEnum("algn", RectAlignment.Bottom);
                rotWithShape = c.GetOptionalBoolean("rotWithShape", true);
            }
        }

        internal override void WriteXmlCore(WriteContext context)
        {
            using (WriteContext c = context.Write("reflection"))
            {
                c.SetOptionalInteger("blurRad", BlurRadius, 0);
                c.SetOptionalInteger("stA", StA, 100000);
                c.SetOptionalInteger("stPos", stPos, 0);
                c.SetOptionalInteger("endA", endA, 0);
                c.SetOptionalInteger("endPos", endPos, 100000);
                c.SetOptionalInteger("dist", dist, 0);
                c.SetOptionalInteger("dir", dir, 0);
                c.SetOptionalInteger("fadeDir", fadeDir, 5400000);
                SerializationHelper.SetOptionalPercent(c, "sx", Sx, 100000);
                SerializationHelper.SetOptionalPercent(c, "sy", Sy, 100000);
                c.SetOptionalInteger("kx", kx, 0);
                c.SetOptionalInteger("ky", ky, 0);
                c.SetOptionalEnum("algn", algn, RectAlignment.Bottom);
                c.SetOptionalBoolean("rotWithShape", rotWithShape, true);
            }
        }

        public override BitmapEffect BitmapEffect(ColorScheme colorScheme)
        {
            {
                throw new NotImplementedException();
            }
        }
    }
}